package ice;
import com.guo.util.ResourceUtil;
import com.slice2java.HelloPrx;

public class Client {
    /***
     * 启动客户端
     * @param communicator .
     * @return int
     */
    private static int run(com.zeroc.Ice.Communicator communicator) {
        System.out.println("创建客户端代理...");
        HelloPrx helloPrx = HelloPrx.checkedCast(communicator.propertyToProxy("Hello.Proxy")).ice_twoway().ice_secure(false);
        if (helloPrx == null) {
            System.err.println("invalid proxy");
            return 1;
        }
        int i =0;
        // 调用Server 模拟通信
        System.out.println("准备发送数据...");
        while (i>=0){
            i++;
            System.out.println("发送数据："+i);
            helloPrx.sayHello("hello-"+i);
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        return 0;
    }
    public static void main(String[] args) {
        String clientConfigPath = ResourceUtil.getResourcePath("/ice/config.client");
        int status = 0;
        java.util.List<String> extraArgs = new java.util.ArrayList<>();
        //
        // try with resource block - communicator is automatically destroyed
        // at the end of this try block
        //
        try (com.zeroc.Ice.Communicator communicator = com.zeroc.Ice.Util.initialize(args, clientConfigPath, extraArgs)) {
            if (!extraArgs.isEmpty()) {
                System.err.println("too many arguments");
                status = 1;
            } else {
                status = run(communicator);
            }
        }
        System.exit(status);
    }
}
